/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the vst4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.hexu.sharedb.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexu.sharedb.component.R;
import com.hexu.sharedb.entity.TsShardingKey;
import com.hexu.sharedb.service.TsShardingKeyService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequiredArgsConstructor
@RequestMapping("/TsShardingKey")
public class TsShardingKeyController {

    private final TsShardingKeyService TsShardingKeyService;

    /**
     * 分页查询
     *
     * @param page          分页对象
     * @param TsShardingKey
     * @return
     */
    @GetMapping("/page")
    public R getTsShardingKeyPage(Page page, TsShardingKey TsShardingKey) {
        return R.ok(TsShardingKeyService.page(page, Wrappers.query(TsShardingKey)));
    }


    /**
     * 通过month查询
     *
     * @param month month
     * @return R
     */
    @GetMapping("/{month}")
    public R<List<TsShardingKey>> getById(@PathVariable("month") String month) {
        return R.ok(TsShardingKeyService.like(month));
    }

    /**
     * 新增
     *
     * @param TsShardingKey
     * @return R
     */
    @PostMapping
    public R save(@RequestBody List<TsShardingKey> TsShardingKey) {
        return R.ok(TsShardingKeyService.saveBatch(TsShardingKey));
    }

    /**
     * 修改
     *
     * @param TsShardingKey
     * @return R
     */
    @PutMapping
    public R updateById(@RequestBody TsShardingKey TsShardingKey) {
        return R.ok(TsShardingKeyService.updateById(TsShardingKey));
    }

    /**
     * 通过id删除
     *
     * @param id id
     * @return R
     */
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Integer id) {
        return R.ok(TsShardingKeyService.removeById(id));
    }

}
